package www.geek.filemanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import www.geek.filemanager.R;
import www.geek.filemanager.bean.AppInfo;

/**
 * description	:
 *
 * @author : zhanggeng
 * @date : 15/7/30
 * @version     : v1.0
 * ----------修订历史-----------
 */
public class AppManagerAdapter extends BaseAdapter{

    private Context mContext;

    private List<AppInfo> mAppInfos;


    public AppManagerAdapter(Context context , List<AppInfo> appInfos){
        mContext = context;
        mAppInfos = appInfos;
    }

    @Override
    public int getCount() {
        return mAppInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

//        View view = LayoutInflater.from(mContext).inflate(R.layout.item_app , null);

        if(convertView == null){
                convertView = LayoutInflater.from(mContext).inflate(R.layout.item_app , null);

                holder = new ViewHolder();

                holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
                holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
                holder.tv_version = (TextView) convertView.findViewById(R.id.tv_version);
                holder.tv_start = (TextView) convertView.findViewById(R.id.tv_start);
                holder.tv_run = (TextView) convertView.findViewById(R.id.tv_app_run);
                holder.cb_checked = (CheckBox) convertView.findViewById(R.id.cb_app_checked);

                convertView.setTag(holder);
        }else{
                convertView.getTag();
        }

        AppInfo appInfo = mAppInfos.get(position);

        holder.imageView.setImageDrawable(appInfo.getAppIcon());
        holder.tv_name.setText(appInfo.getAppName());
        holder.tv_version.setText(appInfo.getAppVersion());
        holder.tv_start.setText("自启动");
        holder.tv_run.setText("运行中");

        return convertView;
    }

    public class ViewHolder{

        public ImageView imageView;
        public TextView tv_name;
        public TextView tv_version;
        public TextView tv_start;
        public TextView tv_run;

        public CheckBox cb_checked;
    }

}
